<?php

class Application_Model_TimeZoneList {

    protected $tzones = array();
    protected $regions = array(
        'Africa'        => DateTimeZone::AFRICA,
        'America'       => DateTimeZone::AMERICA,
        'Antarctica'    => DateTimeZone::ANTARCTICA,
        'Aisa'          => DateTimeZone::ASIA,
        'Atlantic'      => DateTimeZone::ATLANTIC,
        'Europe'        => DateTimeZone::EUROPE,
        'Indian'        => DateTimeZone::INDIAN,
        'Pacific'       => DateTimeZone::PACIFIC
    );

    public function __construct() {
        
    }

    public function __destruct() {
        
    }

    public function getTZList() {
        foreach ($this->regions as $name => $mask) {
            $tzlist[$name] = $this->convertList($mask);
        }
        return $tzlist;
    }

    private function convertList($mask) {
        $tempList = array();
        $tempList = DateTimeZone::listIdentifiers($mask);
        foreach ($tempList as $id => $mask) {
            $new_arr[$mask] = $mask;
        }
        return $new_arr;
    }

    public function getNativeNamesForLocales() {
        $config = new Zend_Config_Json(
                        APPLICATION_PATH . '/configs/localelist.json');
        $localeInstance = Zend_Registry::get('Locale');
        $localeName = $localeInstance->getLanguage();
        $code2name = Zend_Locale::getTranslationList('language', "en_US");
        $code2Tname = Zend_Locale::getTranslationList('territory', $localeName, 2);
        $name2code = array_flip($code2name);
        $list = $config->toArray();
        foreach ($list as $key => $value) {
            $oindex = Zend_Locale::getTranslation($name2code[$key], 'language', $localeName);
            foreach ($value as $key2 => $value2) {
                $territory = explode("_", $key2);
                $innerArray[$key2] = $code2Tname[$territory[1]] . " (" . $key2 . ")";
            }
            $outputArray[$oindex] = $innerArray;
            $innerArray = array();
        }
        return $outputArray;
    }

}

?>